<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>display()</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
<link rel="home" href="index.html" title="Smarty 3 Manual">
<link rel="up" href="api.functions.html" title="Chapter 14. Smarty Class Methods">
<link rel="prev" href="api.disable.security.html" title="disableSecurity()">
<link rel="next" href="api.enable.security.html" title="enableSecurity()">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<div class="navheader">
<table width="100%" summary="Navigation header">
<tr><th colspan="3" align="center">display()</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="api.disable.security.html">Prev</a> </td>
<th width="60%" align="center">Chapter 14. Smarty Class Methods</th>
<td width="20%" align="right"> <a accesskey="n" href="api.enable.security.html">Next</a>
</td>
</tr>
</table>
<hr>
</div>
<div class="refentry" title="display()">
<a name="api.display"></a><div class="titlepage"></div>
<div class="refnamediv">
<h2>Name</h2>
<p>display() — displays the template</p>
</div>
<div class="refsect1" title="Description">
<a name="id432062"></a><h2>Description</h2>
<code class="methodsynopsis"><span class="type">void </span><span class="methodname">display</span>(<span class="methodparam"><span class="type">string </span><span class="parameter">template</span></span>,<br>             <span class="methodparam"><span class="type">string </span><span class="parameter">cache_id</span></span>,<br>             <span class="methodparam"><span class="type">string </span><span class="parameter">compile_id</span></span>);</code><p>
   This displays the contents of a template. To return the contents of a template into
   a variable, use <a class="link" href="api.fetch.html" title="fetch()"><code class="varname">fetch()</code></a>.
   Supply a valid <a class="link" href="resources.html" title="Chapter 16. Resources">template resource</a>
   type and path. As an optional second parameter, you can pass a
   <em class="parameter"><code>$cache_id</code></em>, see the
   <a class="link" href="caching.html" title="Chapter 15. Caching">caching section</a> for more information.
  </p>
<p>
 As an optional third parameter, you can pass a
 <em class="parameter"><code>$compile_id</code></em>.
 This is in the event that you want to compile different versions of
 the same template, such as having separate templates compiled
 for different languages. You can
 also set the <a class="link" href="variable.compile.id.html" title="$compile_id">
 <em class="parameter"><code>$compile_id</code></em></a> variable once instead of passing
  this to each call to this function.
</p>
<div class="example">
<a name="id432561"></a><p class="title"><b>Example 14.19. display()</b></p>
<div class="example-contents"><pre class="programlisting">

&lt;?php
include(SMARTY_DIR.'Smarty.class.php');
$smarty = new Smarty();
$smarty-&gt;setCaching(true);

// only do db calls if cache doesn't exist
if(!$smarty-&gt;isCached('index.tpl')) {

  // dummy up some data
  $address = '245 N 50th';
  $db_data = array(
               'City' =&gt; 'Lincoln',
               'State' =&gt; 'Nebraska',
               'Zip' =&gt; '68502'
             );

  $smarty-&gt;assign('Name', 'Fred');
  $smarty-&gt;assign('Address', $address);
  $smarty-&gt;assign('data', $db_data);

}

// display the output
$smarty-&gt;display('index.tpl');
?&gt;

   </pre></div>
</div>
<br class="example-break"><div class="example">
<a name="id432587"></a><p class="title"><b>Example 14.20. Other display() template resource examples</b></p>
<div class="example-contents">
<p>
   Use the syntax for <a class="link" href="resources.html" title="Chapter 16. Resources">template resources</a> to
   display files outside of the
   <a class="link" href="variable.template.dir.html" title="$template_dir">
   <em class="parameter"><code>$template_dir</code></em></a> directory.
  </p>
<pre class="programlisting">

&lt;?php
// absolute filepath
$smarty-&gt;display('/usr/local/include/templates/header.tpl');

// absolute filepath (same thing)
$smarty-&gt;display('file:/usr/local/include/templates/header.tpl');

// windows absolute filepath (MUST use "file:" prefix)
$smarty-&gt;display('file:C:/www/pub/templates/header.tpl');

// include from template resource named "db"
$smarty-&gt;display('db:header.tpl');
?&gt;

   </pre>
</div>
</div>
<br class="example-break"><p>
   See also <a class="link" href="api.fetch.html" title="fetch()"><code class="varname">fetch()</code></a> and
   <a class="link" href="api.template.exists.html" title="templateExists()"><code class="varname">templateExists()</code></a>.
  </p>
</div>
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="api.disable.security.html">Prev</a> </td>
<td width="20%" align="center"><a accesskey="u" href="api.functions.html">Up</a></td>
<td width="40%" align="right"> <a accesskey="n" href="api.enable.security.html">Next</a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">disableSecurity() </td>
<td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td>
<td width="40%" align="right" valign="top"> enableSecurity()</td>
</tr>
</table>
</div>
</body>
</html>
